package top.fzqblog.config;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.fzqblog.Utils.StringUtil;
import top.fzqblog.model.Param;
import top.fzqblog.model.User;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Component
public class ScheduledTask {


    @Scheduled(cron = "0 0 0 * * ?")
    public void reportCurrentTimeAfterSleep() throws InterruptedException {
        Param param = new Param().selectOne(new EntityWrapper<Param>().eq("param_name", "dayJoinCount"));
        int daycount = 10;
        if(param != null && StringUtil.isNotEmpty(param.getParamValue())){
            daycount = Integer.parseInt(param.getParamValue());
        }

        List<User> users = new User().selectAll();
        for (User user : users) {
            user.setDayJoinCount(daycount);
            user.updateById();
        }
    }

}